package com.ymttest.business.service;

import com.ymatou.iapi.pushbind.parameter.*;
import com.ymatou.iapi.pushbind.parameter.Enum.AppIdType;
import com.ymatou.iapi.pushbind.parameter.Enum.PhoneType;
import com.ymatou.iapi.pushbind.parameter.Enum.UserSystemType;
import com.ymatou.iapi.pushbind.service.BindUserClientCall;
import com.ymatou.iapi.pushbind.service.SavePushConfigCall;
import com.ymatou.iapi.pushbind.service.SaveSellerPushConfigCall;
import com.ymatou.iapi.pushbind.service.UnBindUserClientCall;
import com.ymttest.utils.YMTDateUtil;

import java.io.IOException;

/**
 * IM个推
 */
public class PushCallService {

    /**
     * 初始化绑定用户客户端
     * @param userId
     * @return
     */
    public static BindUserClientBean intitUserClient(int userId){
        BindUserClientBean binduserclientBean = new BindUserClientBean();
        String appId= "pushbind.iapi.com";
        binduserclientBean.setAppId(appId);
        binduserclientBean.setUserSystemType(UserSystemType.YmatouUser);
        binduserclientBean.setAppIdType(AppIdType.SocketIo);
        binduserclientBean.setPhoneType(PhoneType.Web);
        binduserclientBean.setUserId(userId);
        String deviceId = "xiaomage"+YMTDateUtil.getBeforeOrNextSecond(1);
        binduserclientBean.setDeviceId(deviceId);
        String clientId = "Test" + YMTDateUtil.getDate();
        binduserclientBean.setClientId(clientId);
        String deviceIdToken = "Test123" + YMTDateUtil.getDate();
        binduserclientBean.setDeviceToken(deviceIdToken);
        return binduserclientBean;
    }

    /**
     * 绑定用户客户端
     * @param bindUserClientBean
     */
    public static void bindUserClient(BindUserClientBean bindUserClientBean) throws IOException {
        BindUserClientCall bindCall = new BindUserClientCall();
        bindCall.setData(bindUserClientBean);
        bindCall.callService();
    }

    /**
     * 初始化解绑用户客户端bean
     * @param bindUserClientBean
     * @return
     */
    public static UnBindUserClientBean initUnBindUserClient(BindUserClientBean bindUserClientBean){
        UnBindUserClientBean unbinduserclientBean = new UnBindUserClientBean();
        unbinduserclientBean.setAppId(bindUserClientBean.getAppId());
        unbinduserclientBean.setAppIdType(bindUserClientBean.getAppIdType());
        unbinduserclientBean.setClientId(bindUserClientBean.getClientId());
        unbinduserclientBean.setDeviceId(bindUserClientBean.getDeviceId());
        unbinduserclientBean.setDeviceToken("token" + YMTDateUtil.getDate());
        unbinduserclientBean.setUserId(bindUserClientBean.getUserId());
        unbinduserclientBean.setPhoneType(bindUserClientBean.getPhoneType());
        unbinduserclientBean.setUserSystemType(bindUserClientBean.getUserSystemType());
        return unbinduserclientBean;
    }

    /**
     * 解绑用户客户端
     * @param unBindUserClientBean
     * @throws IOException
     */
    public static void UnBindUserClient(UnBindUserClientBean unBindUserClientBean) throws IOException {
        UnBindUserClientCall unbinduserclientCall = new UnBindUserClientCall();
        unbinduserclientCall.setData(unBindUserClientBean);
        unbinduserclientCall.callService();
    }

    /**
     * 初始化买手推送配置
     * @param userId
     * @return
     */
    public static SavePushConfigBean initSavePushConfig(int userId){
        SavePushConfigBean savePushConfigBean = new SavePushConfigBean();
        BuyerPushConfig buyerPushConfig = new BuyerPushConfig();
        buyerPushConfig.setUserId(userId);
        buyerPushConfig.setInteractiveMsgSwitch(1);
        buyerPushConfig.setNotificationSwitch(1);
        buyerPushConfig.setOrderAssistantSwitch(1);
        buyerPushConfig.setPromotionsSwitch(1);
        savePushConfigBean.setConfigInfo(buyerPushConfig);
        return savePushConfigBean;
    }

    /**
     * 保存或修改买家推送配置
     * @param savePushConfigBean
     * @throws IOException
     */
    public static void savePushConfig(SavePushConfigBean savePushConfigBean) throws IOException {
        SavePushConfigCall savePushConfigCall = new SavePushConfigCall();
        savePushConfigCall.setData(savePushConfigBean);
        savePushConfigCall.callService();
    }


    /**
     * 初始化买手推送配置
     * @param userId
     * @return
     */
    public static SaveSellerPushConfigBean initSaveSellerPushConfig(int userId){
        SaveSellerPushConfigBean sellerPushConfigBean = new SaveSellerPushConfigBean();
        String clientId = "Test" + YMTDateUtil.getDate();
        SellerPushConfig sellerPushConfig = new SellerPushConfig();
        sellerPushConfig.setUserId(userId);
        sellerPushConfig.setClientId(clientId);
        sellerPushConfig.setInteractiveMsgSwitch(1);
        sellerPushConfig.setOrderStatusSwitch(1);
        sellerPushConfig.setOrderUnPaySwitch(1);
        sellerPushConfig.setSocialMessageSwitch(1);
        sellerPushConfig.setTransactionSwitch(1);
        sellerPushConfigBean.setConfigInfo(sellerPushConfig);
        return sellerPushConfigBean;
    }


    /**
     * 保存或修改买手推送配置
     * @param sellerPushConfigBean
     * @throws IOException
     */
    public static void saveSellerPushConfig(SaveSellerPushConfigBean sellerPushConfigBean) throws IOException {
        SaveSellerPushConfigCall sellerPushConfigCall = new SaveSellerPushConfigCall();
        sellerPushConfigCall.setData(sellerPushConfigBean);
        sellerPushConfigCall.callService();
    }

}
